package boogui.member;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import boogui.db.BooguiDAO;
import boogui.db.IBooguiDAO;
import boogui.db.MemberSQL;

/**
 * 중복 검사
 */

public class MemberChkDAO implements IMemberChkDAO{
	IBooguiDAO bdao = null;
	MemberSQL msql = null;
	
	public MemberChkDAO() {
		bdao = new BooguiDAO();
		msql = new MemberSQL();
	}

	@Override
	public boolean chkD(String sql, String val) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		boolean result = false;

		try {
			conn = bdao.openDatabase();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, val);
			rs = pstmt.executeQuery();

			if (rs.next()) {
				result = true; // 값이 있으면 true 중복
			} else {
				result = false; // 값이 없으면 false 중복아님
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			bdao.closeDatabase(conn, pstmt, rs);
		}
		return result;
	}

}
